package sma.fbss.agent;

import sma.fbss.model.MDPurchase;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

public class Seller extends Agent 
{
	private static final long serialVersionUID = 1L;

	protected void setup() 
    {
		DFAgentDescription dfd = new DFAgentDescription();
		dfd.setName(getAID());
		ServiceDescription sd = new ServiceDescription();
		sd.setType("seller");
		sd.setName("service-seller");
		dfd.addServices(sd);

		try {
			DFService.register(this, dfd);
		} catch (FIPAException fe) {
			fe.printStackTrace();
		}
    	addBehaviour(new SellerService());
	}
	
	private class SellerService extends CyclicBehaviour {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		
		public void action() 
		{
			ACLMessage msg= receive();

            if(msg != null)
            {
                ACLMessage reply = new ACLMessage( ACLMessage.INFORM );
                reply.setConversationId("footballer-trade");
                reply.setContent( "Pong: repond de " + msg.getContent() + " de " + msg.getSender() );
                System.out.println("me: " + msg.getContent());
                //reply.addReceiver( msg.getSender() );
                //send(reply);
            }
            block();
		}
	

	}

}